<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="button" value="开始计数" onclick="startCount()">
    <input type="text" id="num">
    <input type="button" value="停止计数" onclick="stopCount()">
    <script>
    var timer=null,c=0;
    function timedCount(){//在文本框中显示数据
    document.getElementById('num').value=c;
    ++c;//显示数据+1
    }function startCount(){//开始间接调用
    timer=setInterval(timedCount,1000);
    }function stopCount(){//清除间接调用
    clearInterval(timer);
    }
    </script>
</body>
</html>